home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / wschesb1.zip / SRC / STATUSBR.C < prev    next >
C/C++ Source or Header  |  1994-03-15  |  6KB  |  189 lines

  1. /*
  2.   C source for Winsock Chess
  3.   
  4.   Revision 1994-03-15
  5.   Modified by Donald Munro for use as a 2 player chess game over a 
  6.   WINSOCK layer on a TCP (or other WinSock supporting) network.
  7.   Source code and make files for MS Visual C/C++ V1.00/1.50.
  8.   February/March 1994
  9.   All GNU copyright and distribution conditions as described below and in the
  10.   file COPYING also apply to WinSock Chess.
  11.   This module is Winsock Chess specific.
  12.   
  13.   C source for GNU CHESS
  14.  
  15.   Revision: 1990-09-30
  16.   Modified by Daryl Baker for use in MS WINDOWS environment
  17.  
  18.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  19.   Copyright (c) 1988, 1989, 1990  John Stanback
  20.  
  21.   This file is part of CHESS.
  22.  
  23.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  24.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  25.   the consequences of using it or for whether it serves any particular
  26.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  27.   General Public License for full details.
  28.  
  29.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  30.   only under the conditions described in the CHESS General Public License.
  31.   A copy of this license is supposed to have been given to you along with
  32.   CHESS so you can know your rights and responsibilities.  It should be in a
  33.   file named COPYING.  Among other things, the copyright notice and this
  34.   notice must be preserved on all copies.
  35. */
  36.  
  37.  
  38. #define STRICT
  39.  
  40. #include <windows.h> 
  41. #include <windowsx.h>
  42. #include <shellapi.h>
  43. #include <string.h>
  44.  
  45. #include "gnuchess.h"
  46. #include "defs.h"    
  47.  
  48. #define LEFT_MARGIN 10
  49. #define STATLWIDTH   2
  50. #define STATSEP     18
  51.  
  52. extern BOOL bConnected;
  53. extern int User_Move;
  54. extern short opponent,GameCnt;
  55. extern int ychar;
  56. extern HWND hwndStatus;
  57.  
  58. void Draw3D(HDC hDC, const RECT *rect)
  59. //------------------------------------
  60. { POINT ptTop,ptBot;
  61.   HPEN hpenBlack,hpenWhite,hpenOld;
  62.   int i;
  63.               
  64.   ptTop.x = rect->left-1;
  65.   ptTop.y = rect->top-1;
  66.   ptBot.x = rect->right+1;
  67.   ptBot.y = rect->bottom+1;
  68.   hpenBlack = CreatePen(PS_SOLID,1,RGB(0X60,0X60,0X60));  
  69.   hpenWhite = CreatePen(PS_SOLID,1,RGB(240,240,240));
  70.   hpenOld = SelectObject(hDC,hpenWhite);
  71.   for (i=0; i < STATLWIDTH; i++)
  72.     { SelectObject(hDC,hpenWhite);
  73.       MoveTo(hDC,ptTop.x-i,ptBot.y+i);
  74.       LineTo(hDC,ptBot.x+i,ptBot.y+i);
  75.       LineTo(hDC,ptBot.x+i,ptTop.y-i);
  76.       SelectObject(hDC,hpenBlack);
  77.       LineTo(hDC,ptTop.x-i,ptTop.y-i);
  78.       LineTo(hDC,ptTop.x-i,ptBot.y+i);
  79.     }  
  80.   SelectObject(hDC,hpenOld);
  81.   DeleteObject(hpenBlack);
  82.   DeleteObject(hpenWhite);
  83. }
  84.  
  85. void DrawStatusBar(HWND hwnd)
  86. //---------------------------
  87. { RECT rc;
  88.   PAINTSTRUCT ps;
  89.   HDC hDC;
  90.   int nx,ny;
  91.   DWORD dwExtent;
  92.   COLORREF colBack, colWin;
  93.   char szStr[200],szTime[21],szMax1[]="Not Connected",szMax2[]="Black", 
  94.        szMax3[]="Opponents Move",szMax4[]="Move 8888",
  95.        szMax5[]="Time XXX:XX";
  96.   
  97.   hDC = BeginPaint (hwnd, &ps);
  98.   colBack = GetNearestColor(hDC,RGB(0,255,255));
  99.   colWin  = GetNearestColor(hDC,RGB(0XC0,0XC0,0XC0));
  100.   SetTextColor(hDC,RGB(0,0,0));
  101.   SetBkColor(hDC,colWin);
  102.   nx = LEFT_MARGIN;
  103.   ny = 8;
  104.   if (bConnected)
  105.     lstrcpy(szStr,"Connected    ");
  106.   else
  107.     lstrcpy(szStr,"Not Connected");  
  108.   dwExtent = GetTextExtent(hDC,szStr,lstrlen(szStr));
  109.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  110.   ExtTextOut(hDC,nx,ny,ETO_CLIPPED,&rc,szStr,lstrlen(szStr),(LPINT) NULL);
  111.   dwExtent = GetTextExtent(hDC,szMax1,lstrlen(szMax1));
  112.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  113.   Draw3D(hDC,&rc);             
  114.   
  115.   nx += LOWORD(dwExtent)+STATSEP;
  116.   if (opponent == white)
  117.     lstrcpy(szStr,"White");
  118.   else
  119.     lstrcpy(szStr,"Black");
  120.   if (! bConnected)
  121.     lstrcpy(szStr,"   ");  
  122.   dwExtent = GetTextExtent(hDC,szStr,lstrlen(szStr));  
  123.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  124.   ExtTextOut(hDC,nx,ny,ETO_CLIPPED,&rc,szStr,lstrlen(szStr),(LPINT) NULL);
  125.   dwExtent = GetTextExtent(hDC,szMax2,lstrlen(szMax2));
  126.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  127.   Draw3D(hDC,&rc);
  128.   
  129.   nx += LOWORD(dwExtent)+STATSEP;
  130.   if (User_Move)
  131.     lstrcpy(szStr,"Your Move");
  132.   else
  133.     lstrcpy(szStr,"Opponents Move");
  134.   if (! bConnected)
  135.     lstrcpy(szStr,"   ");    
  136.   dwExtent = GetTextExtent(hDC,szStr,lstrlen(szStr));  
  137.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  138.   ExtTextOut(hDC,nx,ny,ETO_CLIPPED,&rc,szStr,lstrlen(szStr),(LPINT) NULL);
  139.   dwExtent = GetTextExtent(hDC,szMax3,lstrlen(szMax3));
  140.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  141.   Draw3D(hDC,&rc);
  142.   
  143.   nx += LOWORD(dwExtent)+STATSEP;
  144.   wsprintf(szStr,"Move %d",(GameCnt+1)/2);
  145.   if (! bConnected)
  146.     lstrcpy(szStr,"   ");    
  147.   dwExtent = GetTextExtent(hDC,szStr,lstrlen(szStr));  
  148.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  149.   ExtTextOut(hDC,nx,ny,ETO_CLIPPED,&rc,szStr,lstrlen(szStr),(LPINT) NULL);
  150.   dwExtent = GetTextExtent(hDC,szMax4,lstrlen(szMax4));
  151.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  152.   Draw3D(hDC,&rc);
  153.   
  154.   nx += LOWORD(dwExtent)+STATSEP;
  155.   ClockString(szTime);
  156.   wsprintf(szStr,"Time %s",(LPSTR)szTime);
  157.   if (! bConnected)
  158.     lstrcpy(szStr,"   ");    
  159.   dwExtent = GetTextExtent(hDC,szStr,lstrlen(szStr));  
  160.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  161.   ExtTextOut(hDC,nx,ny,ETO_CLIPPED,&rc,szStr,lstrlen(szStr),(LPINT) NULL);
  162.   dwExtent = GetTextExtent(hDC,szMax5,lstrlen(szMax5));
  163.   SetRect(&rc,nx,ny,nx+LOWORD(dwExtent),ny+HIWORD(dwExtent));
  164.   Draw3D(hDC,&rc);
  165.   
  166.   EndPaint (hwnd,&ps);  
  167. }  
  168.  
  169. BOOL DestroyStatusBar(HWND hWnd)
  170. //------------------------------
  171. { PostQuitMessage(0);
  172.   return TRUE;
  173. }  
  174.  
  175. LRESULT CALLBACK StatusBarProc(HWND hWnd,UINT message,WPARAM wParam,
  176.                                LPARAM lParam)
  177. //------------------------------------------------------------------
  178. { switch (message)
  179.    { case WM_PAINT :
  180.        return HANDLE_WM_PAINT(hWnd,wParam,lParam,DrawStatusBar);
  181.        
  182.      case WM_DESTROY:  
  183.           return HANDLE_WM_DESTROY(hWnd,wParam,lParam,DestroyStatusBar);
  184.           
  185.      default:   
  186.          return (DefWindowProc(hWnd, message, wParam, lParam));
  187.    }
  188.   return NULL;
  189. }